package com.tjsinfo.tjsoa.bylaws.action;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.bylaws.bo.IBylawsBO;
import com.tjsinfo.tjsoa.bylaws.dao.IBylawsDao;
import com.tjsinfo.tjsoa.bylaws.vo.Bylaws;

import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.workplan.bo.IWorkPlanMainBo;

public class BylawsControlAction extends Action{
	
	private IBylawsBO bylawsManager;

	public void setBylawsManager(IBylawsBO bylawsManager) {
		this.bylawsManager = bylawsManager;
	}
	private ISystemUserBo tjsUserBo;
	public ISystemUserBo getTjsUserBo() {
		return tjsUserBo;
	}

	public void setTjsUserBo(ISystemUserBo tjsUserBo) {
		this.tjsUserBo = tjsUserBo;
	}
	private IWorkPlanMainBo workPlanMainBo;
	public IWorkPlanMainBo getWorkPlanMainBo() {
		return workPlanMainBo;
	}

	public void setWorkPlanMainBo(IWorkPlanMainBo workPlanMainBo) {
		this.workPlanMainBo = workPlanMainBo;
	}
	public ActionForward execute(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){		
		
		try{

			HttpSession session=request.getSession();
			User user = (User)session.getAttribute("user");
						
			
			String id=request.getParameter("id");
			List bylaws=null;
			bylaws=bylawsManager.findByProperty("id", id);
			request.setAttribute("bylaws", bylaws);

			
			String cid=(String)request.getParameter("cid");
			
					
			// 取得配置文件中的信息
			Properties props = new Properties();
		    ClassLoader cl = this.getClass().getClassLoader();
			InputStream is = cl.getResourceAsStream("com/tjsinfo/tjsoa/bylaws/properties/systemResource.properties"); 
			try {
				props.load(is);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} 
			String c = props.getProperty("tzsh");
			String d = props.getProperty("gzzdsh");
			List list = null;
			
			if (cid.equals("2")){
				list = tjsUserBo.selectByRloesGroup(Integer.parseInt(c) ); 
			}else{
				list = tjsUserBo.selectByRloesGroup(Integer.parseInt(d) ); 
			}
			
			request.setAttribute("list", list);
			workPlanMainBo.selectMapWorkPlanMain(request);
			
			request.setAttribute("type", request.getParameter("type"));
			return mapping.findForward("update");
			
		}catch(Exception e){
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}

}
